﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.ComponentModel;
using NetJsWire.Lite.Converters;
using Newtonsoft.Json;

namespace NetJsWire.Lite.Widgets
{
    [JsonObject]
//    [Serializable]
    public class EventOptions
    {
        [DefaultValue( ( string ) null )]
        [Description( "The scope (this reference) in which the handler function is executed. If omitted, defaults to the object which fired the event." )]
        [JsonProperty( "scope" )]
        [JsonConverter( typeof( NotQuotedJsonStringConverter ) )]
        public string Scope { get; set; }

        [DefaultValue( 0 )]
        [Description( "The number of milliseconds to delay the invocation of the handler after the event fires." )]
        [JsonProperty( "delay" )]
        public int Delay { get; set; }

        [DefaultValue( false )]
        [Description( "True to add a handler to handle just the next firing of the event, and then remove itself." )]
        [JsonProperty( "single" )]
        public bool Single { get; set; }

        [DefaultValue( 0 )]
        [Description( "Causes the handler to be scheduled to run in an Ext.util.DelayedTask delayed by the specified number of milliseconds. If the event fires again within that time, the original handler is not invoked, but the new handler is scheduled in its place." )]
        [JsonProperty( "buffer" )]
        public int Buffer { get; set; }

        [DefaultValue( ( string ) null )]
        [Description( "Only call the handler if the event was fired on the target Observable, not if the event was bubbled up from a child Observable." )]
        [JsonProperty( "target" )]
        [JsonConverter( typeof( NotQuotedJsonStringConverter ) )]
        public string Target { get; set; }

        public override string ToString()
        {
            return "Options";
        }

        internal void Clear()
        {
            Scope = null;
            Delay = 0;
            Single = false;
            Buffer = 0;
            Target = null;
        }
    }
}
